﻿

namespace Mulala.Cavan.Presentation.Mvc.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Spring.Context;
    using Spring.Context.Support;
    using Mulala.Cavan.Application.MainBoundedContext.AttachmentModule;
    using Mulala.Cavan.Application.MainBoundedContext.MulalaModule;
    using Mulala.Cavan.Domain.MainBoundedContext.CorporationModule;
    using Mulala.Cavan.Presentation.Seedwork;

    public class CorporationCommentViewModelConverter
    {
        public static IList<ICorporationCommentViewModel> Convert(IList<CorporationComment> corporationComments)
        {
            IApplicationContext springContext = ContextRegistry.GetContext();
            IAttachmentAppService attachmentAppService = springContext.GetObject(MulalaAppServiceConst.ATTACHMENTAPPSERVICE) as IAttachmentAppService;

            IList<ICorporationCommentViewModel> corporationCommentViewModels = new List<ICorporationCommentViewModel>();
            if (null != corporationCommentViewModels)
            {
                foreach (CorporationComment corporationComment in corporationComments)
                {
                    INannyCommentViewModel corporationCommentViewModel = ModelFactory.CreateModel<INannyCommentViewModel>();
                    corporationCommentViewModel.ProprietorID = corporationComment.Proprietor.ID;
                    corporationCommentViewModel.ProprietorName = corporationComment.Proprietor.Name;
                    corporationCommentViewModel.Avatar = attachmentAppService.GetProprietorAvatar(corporationComment.Proprietor);
                }
            }

            return corporationCommentViewModels;
        }
    }
}
